package org.hanyx.server;

import io.grpc.stub.StreamObserver;
import org.hanyx.grpc.call.api.CallRequest;
import org.hanyx.grpc.call.api.CallResponse;
import org.hanyx.grpc.call.api.CallServiceGrpc;

@GrpcService
public class CallServiceImpl extends CallServiceGrpc.CallServiceImplBase {

    @Override
    public void call(CallRequest request, StreamObserver<CallResponse> responseObserver) {
        CallResponse response = null;
        try {
            response = CallResponse
                    .newBuilder()
                    .setMessage("phone = " + request.getPhone())
                    .build();
        } catch (Exception e) {
            responseObserver.onError(e);
        } finally {
            responseObserver.onNext(response);
        }
        // 结束整个响应
        responseObserver.onCompleted();
    }
}
